<?php include('header.php');?>
<?php 
$id = $_GET['id'];

if($_GET['action']=='delete' && $_GET['date']!=""){
	$dQuery = mysql_query("DELETE FROM reservation_session WHERE reservation_checkin = '".$_GET['date']."'");
	if($dQuery){
		echo "<script>window.location='room_edit_detail.php?id=".$id."'</script>";
	}
}

?>
<style type="text/css">
.OnOver {
	cursor:pointer;
}
</style>
<script type="text/javascript">
                    $(function(){
                        var dateBefore=null;
                        $("#AddDate").datepicker({
                            dateFormat: 'yy-mm-dd',
                            dayNamesMin: ['อา', 'จ', 'อ', 'พ', 'พฤ', 'ศ', 'ส'],
                            monthNamesShort: ['มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'],
                            changeMonth: true,
                            minDate: 0,
                            changeYear: true ,
                        });
                    });

	function DateOut(){
		var date = document.getElementById('AddDate').value;
		if(date==""){
			alert('กรุณาเลือกวันที่ด้วยค่ะ');
			document.getElementById('AddDate').focus();
			return false;
		} else {
			<?php 
			$cQuery = mysql_query("SELECT reservation_checkin FROM reservation_session GROUP BY reservation_checkin");
				while($cRow = mysql_fetch_array($cQuery)){
			?>
					if(date=='<?php echo $cRow['reservation_checkin'];?>'){
						alert('วันที่ <?php echo thai_date(strtotime($cRow['reservation_checkin'])); ?> มีอยู่แล้วกรุณาเลือก เพิ่ม/ลด ห้อง  แทนค่ะ');
						document.getElementById('AddDate').value = "";
						return false;
					}
			<?php	
				}
			?>
				window.location='room_edit_date.php?action=add&id=<?php echo $id;?>&date='+date;
		}
	}
</script>
<body onload="onload();">
<form id="form1" name="form1" action="room_edit_add.php?id=<?php echo $id; ?>" method="post">
<div class="box">
  <div class="left"></div>
  <div class="right"></div>
    <div class="heading"><h1>แก้ไขการจองห้องพัก</h1>
    <div class="buttons"><a onclick="CheckSubmit();" class="button"><span>บันทึกการแก้ไข</span></a><a onclick="Javascript:window.location='room_edit.php';" class="button"><span>ยกเลิก</span></a></div>
</div>
  <div class="content">
<fieldset class="ui-corner">
<legend>ข้อมูลห้องพัก</legend>
<?php
$rQuery = mysql_query("SELECT reservation_checkin FROM reservation_session WHERE reservation_detail_id='$id' GROUP BY reservation_checkin ");
$a=0;
while($rRow = mysql_fetch_array($rQuery)){
	$a++;
	$sQuery = mysql_query("SELECT room.room_name as room_name,room.room_pax as room_pax FROM reservation_session,room WHERE room.room_id = reservation_session.room_id AND reservation_session.reservation_checkin = '".$rRow['reservation_checkin']."' AND reservation_session.reservation_detail_id='$id'");
	
	echo "<div style=\"padding-bottom:5px;\"><b> <a href=\"room_edit_date.php?action=edit&id=".$id."&date=".$rRow['reservation_checkin']."\" title=\"เพิ่ม/ลด ห้อง วันที่ ".thai_date(strtotime($rRow['reservation_checkin']))."\"/> <img src=\"../image/Actions-document-edit-icon.png\" /> เพิ่ม/ลด ห้อง </a> &nbsp;&nbsp;วันที่ </b>".thai_date(strtotime($rRow['reservation_checkin']))."<b> &nbsp;&nbsp; <img src=\"../image/Button-Delete-icon.png\" class=\"OnOver\" onclick=\"if(confirm('ยืนยันการลบจองห้องพักวันที่ ".thai_date(strtotime($rRow['reservation_checkin']))."')==true){window.location='room_edit_detail.php?action=delete&id=".$id."&date=".$rRow['reservation_checkin']."';}\" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ห้อง &nbsp;&nbsp;&nbsp;</b>";
	while($sRow = mysql_fetch_array($sQuery)){
		$room_name .= ", <b>".$sRow['room_name']."</b> (พัก ".$sRow['room_pax']." ท่าน)";
		$Room_Pax = $Room_Pax + $sRow['room_pax'];
	}
	echo substr($room_name, 2);
	echo "</div>";
	$room_name = "";

}

?>
<b> <img src="../image/Actions-document-edit-icon.png" /> เพิ่มห้อง &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;วันที่ </b> <input type="text" name="AddDate" id="AddDate" size="11" />&nbsp;&nbsp;&nbsp; <img src="../image/Button-Add-icon.png" class="OnOver" onclick="DateOut();"/>
<!-- 
<br>
<b>อาหารเช้า</b> <br>&nbsp;&nbsp;  <label><input type="radio" name="abf" id="abf1" value="yes" />รวมอาหารเช้า </label>&nbsp;&nbsp;&nbsp; <label><input type="radio" name="abf" id="abf2" value="no" />ไม่รวมอาหารเช้า </label>
 -->
<?php 
//กรณีถ้ามีข้อมูล ABF
$AbfQuery[1] = mysql_query("SELECT * FROM reservation_information WHERE reservation_detail_id='$id' AND more_information_id = '1'");
$AbfRow[1] = mysql_fetch_array($AbfQuery[1]);
	if($AbfRow[1]){
		$AbfChecked[1] = "Checked=\"Checked\"";
		$AbfValue[1] = $AbfRow[1]['more_information_value'];
		$AbfVisible[1] = "visible";
	} else {
		$AbfChecked[1] = "";
		$AbfValue[1] = "";
		$AbfVisible[1] = "hidden";
	}

//กรณีถ้ามีข้อมูล ExtraAbf
$AbfQuery[2] = mysql_query("SELECT * FROM reservation_information WHERE reservation_detail_id='$id' AND more_information_id = '2'");
$AbfRow[2] = mysql_fetch_array($AbfQuery[2]);
	if($AbfRow[2]){
		$AbfChecked[2] = "Checked=\"Checked\"";
		$AbfValue[2] = $AbfRow[2]['more_information_value'];
		$AbfVisible[2] = "visible";
	} else {
		$AbfChecked[2] = "";
		$AbfValue[2] = "";
		$AbfVisible[2] = "hidden";
	}
	
//กรณีถ้ามีข้อมูล Extra
$AbfQuery[3] = mysql_query("SELECT * FROM reservation_information WHERE reservation_detail_id='$id' AND more_information_id = '3'");
$AbfRow[3] = mysql_fetch_array($AbfQuery[3]);
	if($AbfRow[3]){
		$AbfChecked[3] = "Checked=\"Checked\"";
		$AbfValue[3] = $AbfRow[3]['more_information_value'];
		$AbfVisible[3] = "visible";
	} else {
		$AbfChecked[3] = "";
		$AbfValue[3] = "";
		$AbfVisible[3] = "hidden";
	}
	
//กรณีถ้ามีข้อมูล AbfA
$AbfQuery[4] = mysql_query("SELECT * FROM reservation_information WHERE reservation_detail_id='$id' AND more_information_id = '4'");
$AbfRow[4] = mysql_fetch_array($AbfQuery[4]);
	if($AbfRow[4]){
		$AbfChecked[4] = "Checked=\"Checked\"";
		$AbfValue[4] = $AbfRow[4]['more_information_value'];
		$AbfVisible[4] = "visible";
	} else {
		$AbfChecked[4] = "";
		$AbfValue[4] = "";
		$AbfVisible[4] = "hidden";
	}
	
//กรณีถ้ามีข้อมูล AbfC
$AbfQuery[5] = mysql_query("SELECT * FROM reservation_information WHERE reservation_detail_id='$id' AND more_information_id = '5'");
$AbfRow[5] = mysql_fetch_array($AbfQuery[5]);
	if($AbfRow[5]){
		$AbfChecked[5] = "Checked=\"Checked\"";
		$AbfValue[5] = $AbfRow[5]['more_information_value'];
		$AbfVisible[5] = "visible";
	} else {
		$AbfChecked[5] = "";
		$AbfValue[5] = "";
		$AbfVisible[5] = "hidden";
	}
	
//กรณีถ้ามีข้อมูล AddA
$AbfQuery[6] = mysql_query("SELECT * FROM reservation_information WHERE reservation_detail_id='$id' AND more_information_id = '6'");
$AbfRow[6] = mysql_fetch_array($AbfQuery[6]);
	if($AbfRow[6]){
		$AbfChecked[6] = "Checked=\"Checked\"";
		$AbfValue[6] = $AbfRow[6]['more_information_value'];
		$AbfVisible[6] = "visible";
	} else {
		$AbfChecked[6] = "";
		$AbfValue[6] = "";
		$AbfVisible[6] = "hidden";
	}
	
//กรณีถ้ามีข้อมูล AddC
$AbfQuery[7] = mysql_query("SELECT * FROM reservation_information WHERE reservation_detail_id='$id' AND more_information_id = '7'");
$AbfRow[7] = mysql_fetch_array($AbfQuery[7]);
	if($AbfRow[7]){
		$AbfChecked[7] = "Checked=\"Checked\"";
		$AbfValue[7] = $AbfRow[7]['more_information_value'];
		$AbfVisible[7] = "visible";
	} else {
		$AbfChecked[7] = "";
		$AbfValue[7] = "";
		$AbfVisible[7] = "hidden";
	}
?>
<div style="padding-left: 10px; padding-top:20px;">
<table>
	<tr>
		<td><label><input type="checkbox" <?php echo $AbfChecked[1];?> name="Abf" id="Abf" value="<?php echo $Room_Pax;?>" onclick="CheckHideOption();showhide('sAbf','tAbf');" /> รวมอาหารเช้า</label> </td>
		<td><span id="sAbf" style="padding-left:15px; visibility: <?php echo $AbfVisible[1];?>;">จำนวน <input onclick="CheckHideOption();" class="tRight" name="tAbf" type="text" value="<?php echo $AbfValue[1];?>" id="tAbf" size="1"> </span></td>
	</tr>
	<tr>
		<td><label><input type="checkbox" <?php echo $AbfChecked[2];?> name="ExtraAbf" id="ExtraAbf" value="1" onclick="CheckHideOption();showhide('sExtraAbf','tExtraAbf');" /> Extra Bed + ABF</label> </td>
		<td><span id="sExtraAbf" style="padding-left:15px; visibility: <?php echo $AbfVisible[2];?>;">จำนวน <input onclick="CheckHideOption();" class="tRight" name="tExtraAbf" type="text" value="<?php echo $AbfValue[2];?>" id="tExtraAbf" size="1"> </span></td>
	</tr>
	<tr>
		<td><label><input type="checkbox" <?php echo $AbfChecked[3];?> name="Extra" id="Extra" value="2" onclick="CheckHideOption();showhide('sExtra','tExtra');" /> Extra Bed</label></td>
		<td><span id="sExtra" style="padding-left:15px; visibility: <?php echo $AbfVisible[3];?>;">จำนวน <input onclick="CheckHideOption();" class="tRight" name="tExtra" type="text" value="<?php echo $AbfValue[3];?>" id="tExtra" size="1"> </span></td>
	</tr>
	<tr>
		<td><label><input type="checkbox" <?php echo $AbfChecked[4];?> name="AbfA" id="AbfA" value="3" onclick="CheckHideOption();showhide('sAbfA','tAbfA');" /> ABF (ผู้ใหญ่)</label></td>
		<td><span id="sAbfA" style="padding-left:15px; visibility: <?php echo $AbfVisible[4];?>;">จำนวน <input onclick="CheckHideOption();" class="tRight" name="tAbfA" type="text" value="<?php echo $AbfValue[4];?>" id="tAbfA" size="1"> </span></td>
	</tr>
	<tr>
		<td><label><input type="checkbox" <?php echo $AbfChecked[5];?> name="AbfC" id="AbfC" value="4" onclick="CheckHideOption();showhide('sAbfC','tAbfC');" /> ABF (เด็ก)</label></td>
		<td><span id="sAbfC" style="padding-left:15px; visibility: <?php echo $AbfVisible[5];?>;">จำนวน <input onclick="CheckHideOption();" class="tRight" name="tAbfC" type="text" value="<?php echo $AbfValue[5];?>" id="tAbfC" size="1"> </span></td>
	</tr>
	<tr>
		<td><label><input type="checkbox" <?php echo $AbfChecked[6];?> name="AddA" id="AddA" value="5" onclick="CheckHideOption();showhide('sAddA','tAddA');" /> พักเพิ่ม (ผู้ใหญ่)</label></td>
		<td><span id="sAddA" style="padding-left:15px; visibility: <?php echo $AbfVisible[6];?>;">จำนวน <input onclick="CheckHideOption();" class="tRight" name="tAddA" type="text" value="<?php echo $AbfValue[6];?>" id="tAddA" size="1"> </span></td>
	</tr>
	<tr>
		<td><label><input type="checkbox" <?php echo $AbfChecked[7];?> name="AddC" id="AddC" value="6" onclick="CheckHideOption();showhide('sAddC','tAddC');" /> พักเพิ่ม (เด็ก)</label></td>
		<td><span id="sAddC" style="padding-left:15px; visibility: <?php echo $AbfVisible[7];?>;">จำนวน <input onclick="CheckHideOption();" class="tRight" name="tAddC" type="text" value="<?php echo $AbfValue[7];?>" id="tAddC" size="1"> </span></td>
	</tr>
</table>
</div>
</fieldset>
<?php 
//แสดงข้อมูลผู้จอง
$nQuery = mysql_query("SELECT * FROM reservation_detail WHERE reservation_detail_id='$id'");
$nRow = mysql_fetch_array($nQuery);
?>
<fieldset class="ui-corner">
<legend>ข้อมูลผู้จอง</legend>
    <table class="form">
       <tr>
        <td>ชื่อ : </td>
        <td><input name="fname" type="text" id="fname" class="vd_form" value="<?php echo $nRow['reservation_detail_fname'];?>" /></td>
      </tr>
       <tr>
        <td>นามสกุล : </td>
        <td><input name="lname" type="text" id="lname" class="vd_form" value="<?php echo $nRow['reservation_detail_lname'];?>" /></td>
      </tr>      
       <tr>
        <td>ชื่อบริษัท : </td>
        <td><input name="name" type="text" id="name" class="vd_form" value="<?php echo $nRow['reservation_detail_name'];?>" /></td>
      </tr>   
       <tr>
        <td>เบอร์โทรศัพท์ : </td>
        <td><input name="phone" type="text" id="phone" class="vd_form" value="<?php echo $nRow['reservation_detail_phone'];?>" /></td>
      </tr>   
       <tr>
        <td>เบอร์แฟ็กซ์ : </td>
        <td><input name="fax" type="text" id="fax" class="vd_form" value="<?php echo $nRow['reservation_detail_fax'];?>" /></td>
      </tr>   
       <tr>
        <td>อีเมล์ : </td>
        <td><input name="email" type="text" id="email" class="vd_form" value="<?php echo $nRow['reservation_detail_email'];?>" /></td>
      </tr>                                
    </table>
</fieldset>

<fieldset class="ui-corner">
<legend>ข้อมูลการชำระเงิน</legend>
รูปแบบการจอง&nbsp;&nbsp;  <label><input type="radio" name="tResep" id="Group" <?php if($nRow['reservation_detail_payment_information']=='group'){ echo "checked=\"checked\"";} ?> onclick="CheckOption('Group','room_edit_group','','<?php echo $id;?>');GroupCheck();" value="group" />กรุ๊ป </label>&nbsp;&nbsp;&nbsp; <label><input type="radio" <?php if($nRow['reservation_detail_payment_information']=='special'){ echo "checked=\"checked\"";} ?> onclick="CheckOption('Special','room_edit_special','','');GroupUnCheck();" name="tResep" id="Special" value="special" />บริษัททัวร์ </label>&nbsp;&nbsp;&nbsp; <label><input type="radio" <?php if($nRow['reservation_detail_payment_information']=='walkin'){ echo "checked=\"checked\"";} ?> name="tResep" id="walkin" value="walkin" onclick="CheckOption('walkin','room_edit_walkin','','<?php echo $id;?>');GroupUnCheck();" />W/N </label>

<?php 
//กรณีเลือก walkin
if($nRow['reservation_detail_payment_information']=='walkin'){
?>
<script>
function onload(){
	CheckOption('walkin','room_edit_walkin','','<?php echo $id;?>');
}
</script>
<?php 
}
//กรณีเลือก บริษัททัวร์ special
if($nRow['reservation_detail_payment_information']=='special'){
?>
<script>
function onload(){
	CheckOption('','room_edit_special','<?php echo $nRow['group_detail_id'];?>','<?php echo $id;?>');
}
</script>
<?php 
} 

//กรณีเลือก กรุ๊ป Group
if($nRow['reservation_detail_payment_information']=='group'){
?>
<script>
function onload(){
	GroupCheck();
	CheckOption('Group','room_edit_group','','<?php echo $id;?>');
}
</script>
<?php } ?>

<div style="padding-top:15px; width:600px;">
<span id="tourShow" style="display: none;">
<select name="Group_Detail" id="Group_Detail" onchange="CheckOption('','room_edit_special',this.value,'<?php echo $id;?>');">
<option value=""><-- กรุณาเลือกบริษัททัวร์ --></option>
<?php 
	$gQuery = mysql_query("SELECT * FROM group_detail ORDER BY group_detail_name");
	while($gRow = mysql_fetch_array($gQuery)){
?>
<option <?php if($gRow['group_detail_id']==$nRow['group_detail_id']){ echo "selected=\"selected\"";}?> value="<?php echo $gRow['group_detail_id'];?>"><?php echo $gRow['group_detail_name'];?></option>
<?php } ?>
</select></span>

<span id="mySpan"></span></div>
</fieldset>

<fieldset class="ui-corner">
<legend>ข้อมูลรายละเอียดเพิ่มเติม</legend>
<textarea name="remark" rows="5" cols="100"><?php echo $nRow['reservation_detail_detail'];?></textarea>
</fieldset>

<fieldset class="ui-corner">
<legend>ข้อมูลผู้รับจอง</legend>
   <table class="form">
       <tr>
        <td>ชื่อ-นามสกุล : </td>
        <td><input name="name_r" type="text" id="name_r" class="vd_form" value="<?php echo $nRow['reservation_detail_sale_name'];?>"/> <font color="red">**ชื่อผู้ที่รับเรื่องจองจากลูกค้าโดยตรง</font></td>
      </tr>
       <tr>
        <td>เบอร์โทรศัพท์ : </td>
        <td><input name="phone_r" type="text" id="phone_r" value="<?php echo $nRow['reservation_detail_sale_phone'];?>"/></td>
      </tr>                              
    </table>
</fieldset>
  </div>
</div>
</form>
</body>
<?php include('footer.php');?>
